package com.nyist.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.nyist.mq.constant.RocketTagConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * topic需要和生产者的topic一致，
 * consumerGroup属性是必须指定的，内容可以随意, 在rocket控制台中会创建 消费者组
 * selectorExpression的意思指的就是tag，默认为“*”，不设置的话会监听所有消息
 */
@Slf4j
@Service
@RocketMQMessageListener(
        topic = "NYIST_TOPIC",
        consumerGroup = "consumerGroup" + "_" + RocketTagConstant.TAG_SEND,
        selectorExpression = RocketTagConstant.TAG_SEND,
        messageModel = MessageModel.BROADCASTING
)
public class SendTagConsumerServiceImpl implements RocketMQListener<String> {

    @Override
    public void onMessage(String message) {
        log.info("=====消费者>>>tag=" + RocketTagConstant.TAG_SEND + ", 接收到消息为:{}", JSONObject.toJSONString(message));
        // 消费者 处理业务逻辑
    }
}
